import 'dart:convert';

import 'package:factoryside/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
///网页
class WebPage extends StatefulWidget {
  String title;
  String url;
  String html;

  WebPage(this.title, this.url, this.html);

  @override
  _WebState createState() => _WebState(title,url,html);
}

class _WebState extends State<WebPage> {
  String title;
  String url;
  String html;

  _WebState(this.title, this.url, this.html);

  WebViewController _webViewController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:buildAppBar(title,null,context),
      body: url==null&&html==null?Center(child: CircularProgressIndicator()):WebView(
          onWebViewCreated: (WebViewController webViewController) {
            _webViewController = webViewController;
            if (html!=null) {
              _webViewController.loadUrl(Uri.dataFromString(html,
                  mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
                  .toString());
            }
          },
          initialUrl: url==null?'':url,
          //JS执行模式 是否允许JS执行
          javascriptMode: JavascriptMode.unrestricted
      ),
    );
  }
}